package com.core.website.api;

import com.core.website.common.Result;
import com.core.website.common.ResultUtil;
import com.core.website.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/fileApi")
public class FileApi {

    @Autowired
    private FileService fileService;
    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,headers="content-type=multipart/form-data")
    public Result uploadFiles(@RequestBody List<MultipartFile> file) {
        if (file == null||file.size()==0) {
            return ResultUtil.error(7777,"文件不能为空");
//            return "文件不能为空";
        }
        return fileService.uploadFiles(file);
    }

    @GetMapping(value = "/getVisitUrl")
    public Object getVisitUrl(String fileId)  {
        return fileService.getVisitUrl(fileId);
    }
//    @GetMapping(value = "changeFileSaveType/{type}")
//    public Object changeFileSaveType(@PathVariable("type") String type)  {
//        return fileService.changeFileSaveType(type);
//    }
}
